//
//  HCHomeViewController.m
//  hcpro
//
//  Created by hc on 16/9/22.
//  Copyright © 2016年 hucai.com. All rights reserved.
//

#import "HCHomeViewController.h"

#import "HCBannerView.h"
#import "HCGoodsView.h"

@interface HCHomeViewController ()<UITableViewDelegate, UITableViewDataSource>
/** 轮播视图 */
@property (nonatomic, strong) HCBannerView *bannerView;
/** 商品分类视图 */
@property (nonatomic, strong) UITableView *goodsTypeTableView;
/** 商品视图 */
@property (nonatomic, strong) HCGoodsView *goodsView;


@end

@implementation HCHomeViewController

#pragma mark -
#pragma mark ----------------------------life cicle----------------------------
- (void)viewDidLoad {
    [super viewDidLoad];
    // 设置导航栏
    [self setupNav];
    
    // 设置子控件
    [self setupSubViews];
}

#pragma mark -
#pragma mark ----------------------------setup----------------------------
/** 设置导航栏 */
- (void) setupNav{
    // 标题视图
    UIImage *titleImg = [UIImage imageNamed:@"home_navigationItem_title"];
    UIImageView *titleImgView = [[UIImageView alloc] initWithImage:titleImg];
    [self.navigationItem setTitleView:titleImgView];
    
    // 导航栏右边自定义视图(显示消息)
    UIView *rightCustomView = [[UIView alloc] init];
    UIButton *imgBtn = ({
        UIButton *imgBtn = [[UIButton alloc] init];
        [imgBtn setImage:[UIImage imageNamed:@"icon_nav_message"] forState:UIControlStateNormal];
        [imgBtn addTarget:self action:@selector(pushToMyMessageController) forControlEvents:UIControlEventTouchUpInside];
        imgBtn;
    });
    UILabel *badgeLbl = ({
        UILabel *badgeLbl = [[UILabel alloc] init];
        [badgeLbl setTextColor:[UIColor whiteColor]];
        [badgeLbl setFont:HCSmallFont];
        [badgeLbl setText:@"99"];
        badgeLbl;
    });
    [rightCustomView addSubview:imgBtn];
    [rightCustomView addSubview:badgeLbl];
    // 布局
    [rightCustomView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.equalTo(26);
        make.width.equalTo(30);
    }];
    [imgBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.bottom.equalTo(rightCustomView);
        make.width.height.equalTo(20);
    }];
    [badgeLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(rightCustomView);
        make.left.equalTo(imgBtn.right).offset(-5);
    }];
    UIBarButtonItem *rightBarBtnItem = [[UIBarButtonItem alloc] initWithCustomView:rightCustomView];
    [self.navigationItem setRightBarButtonItem:rightBarBtnItem];
    
    
}

/** 设置子控件 */
- (void) setupSubViews{
    // 添加展示视图
    [self.view addSubview:self.goodsTypeTableView];
    
    WEAKSELF
    // 设置展示视图约束
    [self.goodsTypeTableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.equalTo(weakSelf.view);
        make.bottom.equalTo(weakSelf.view).offset(HCNavBarHeight);
        make.width.equalTo(HCScreenW);
    }];
}

#pragma mark -
#pragma mark ----------------------------user define---------------------------
/** 显示我的消息界面 */
- (void) pushToMyMessageController{
    
}

#pragma mark -
#pragma mark ----------------------------delegate & datasource---------------------------
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 5;
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [[UITableViewCell alloc] init];
    cell.textLabel.text = @"********123312*********";
    return cell;
}
- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50;
}

#pragma mark -
#pragma mark ----------------------------lazyload(subviews)----------------------------
/** banner视图 */
- (HCBannerView *)bannerView{
    if (_bannerView == nil) {
        _bannerView = [[HCBannerView alloc] init];
    }
    return _bannerView;
}
/**  商品分类视图 */
- (UITableView *)goodsTypeTableView{
    if (_goodsTypeTableView == nil) {
        _goodsTypeTableView = [[UITableView alloc] init];
        _goodsTypeTableView.dataSource = self;
        _goodsTypeTableView.delegate = self;
        _goodsTypeTableView.tableHeaderView = self.bannerView;
        _goodsTypeTableView.tableFooterView = self.goodsView;;
    }
    return _goodsTypeTableView;
}
/** 商品视图 */
- (HCGoodsView *)goodsView{
    if (_goodsView == nil) {
        _goodsView = [[HCGoodsView alloc] init];
    }
    return _goodsView;
}

#pragma mark -
#pragma mark ----------------------------lazyload(property)----------------------------


@end
